//
//  YesterdayTopModel.m
//
//  Created by mac  on 2018/11/29
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "YesterdayTopModel.h"


NSString *const kYesterdayTopModelSubscriberHeadPic = @"SubscriberHeadPic";
NSString *const kYesterdayTopModelCoinAccount = @"CoinAccount";
NSString *const kYesterdayTopModelSubscriberCode = @"SubscriberCode";
NSString *const kYesterdayTopModelSubscriberNickName = @"SubscriberNickName";
NSString *const kYesterdayTopModelSubscriberID = @"SubscriberID";


@interface YesterdayTopModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation YesterdayTopModel

@synthesize subscriberHeadPic = _subscriberHeadPic;
@synthesize coinAccount = _coinAccount;
@synthesize subscriberCode = _subscriberCode;
@synthesize subscriberNickName = _subscriberNickName;
@synthesize subscriberID = _subscriberID;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.subscriberHeadPic = [self objectOrNilForKey:kYesterdayTopModelSubscriberHeadPic fromDictionary:dict];
            self.coinAccount = [[self objectOrNilForKey:kYesterdayTopModelCoinAccount fromDictionary:dict] doubleValue];
            self.subscriberCode = [self objectOrNilForKey:kYesterdayTopModelSubscriberCode fromDictionary:dict];
            self.subscriberNickName = [self objectOrNilForKey:kYesterdayTopModelSubscriberNickName fromDictionary:dict];
            self.subscriberID = [[self objectOrNilForKey:kYesterdayTopModelSubscriberID fromDictionary:dict] intValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.subscriberHeadPic forKey:kYesterdayTopModelSubscriberHeadPic];
    [mutableDict setValue:[NSNumber numberWithDouble:self.coinAccount] forKey:kYesterdayTopModelCoinAccount];
    [mutableDict setValue:self.subscriberCode forKey:kYesterdayTopModelSubscriberCode];
    [mutableDict setValue:self.subscriberNickName forKey:kYesterdayTopModelSubscriberNickName];
    [mutableDict setValue:[NSNumber numberWithInt:self.subscriberID] forKey:kYesterdayTopModelSubscriberID];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.subscriberHeadPic = [aDecoder decodeObjectForKey:kYesterdayTopModelSubscriberHeadPic];
    self.coinAccount = [aDecoder decodeDoubleForKey:kYesterdayTopModelCoinAccount];
    self.subscriberCode = [aDecoder decodeObjectForKey:kYesterdayTopModelSubscriberCode];
    self.subscriberNickName = [aDecoder decodeObjectForKey:kYesterdayTopModelSubscriberNickName];
    self.subscriberID = [aDecoder decodeIntegerForKey:kYesterdayTopModelSubscriberID];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_subscriberHeadPic forKey:kYesterdayTopModelSubscriberHeadPic];
    [aCoder encodeDouble:_coinAccount forKey:kYesterdayTopModelCoinAccount];
    [aCoder encodeObject:_subscriberCode forKey:kYesterdayTopModelSubscriberCode];
    [aCoder encodeObject:_subscriberNickName forKey:kYesterdayTopModelSubscriberNickName];
    [aCoder encodeInteger:_subscriberID forKey:kYesterdayTopModelSubscriberID];
}

- (id)copyWithZone:(NSZone *)zone
{
    YesterdayTopModel *copy = [[YesterdayTopModel alloc] init];
    
    if (copy) {

        copy.subscriberHeadPic = [self.subscriberHeadPic copyWithZone:zone];
        copy.coinAccount = self.coinAccount;
        copy.subscriberCode = [self.subscriberCode copyWithZone:zone];
        copy.subscriberNickName = [self.subscriberNickName copyWithZone:zone];
        copy.subscriberID = self.subscriberID;
    }
    
    return copy;
}


@end
